<!DOCTYPE html>
<html lang="en">

<head>
  <meta charset="UTF-8">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>Document</title>
</head>

<body>
  <script>
    // 判断当前标签是否为活跃状态
    document.addEventListener("visibilitychange", (evt) => {
      console.log(document.visibilityState);
      if (document.visibilityState === 'hidden') {
        console.log("不活跃");
      }
      else if (document.visibilityState === 'visible') {
        console.log("活跃");
      }
    })
  </script>
</body>

</html>
